package Hxw3DEngine.core.component.renderer 
{
	//import Hxw3DEngine.asset.parsers.bson.vo.MaterialBase;
	import flash.display3D.Context3D;
	import flash.display3D.IndexBuffer3D;
	import Hxw3DEngine.core.component.Component3D;
	import Hxw3DEngine.core.component.renderer.Renderer3D;
	import Hxw3DEngine.core.controller.Camera3D;
	import Hxw3DEngine.core.controller.RenderTree;
	import Hxw3DEngine.core.display.GameObject;
	import Hxw3DEngine.core.Resource.geometry.ResourceGeometry;
	import Hxw3DEngine.core.materials.Material3D;
	import flash.geom.Matrix3D;
	import Hxw3DEngine.proxy.Stage3DProxy;
	
	/**基本网格渲染组件
	 * @author ...
	 */
	public class MeshRenderer extends Renderer3D 
	{
		
		protected var _material:Material3D;
		
		
		protected var _geometry:ResourceGeometry;
		
		
		//获取网格数据
		public function get geometry():ResourceGeometry{
			return _geometry;
		}
		
		//设置网格数据
		public function set geometry(value:ResourceGeometry):void{
			_geometry = value;
		}
		
		//获得纹理
		public function get material():Material3D{
			return _material;
		}
		
		//设置纹理
		public function set material(value:Material3D):void{
			_material = value;
		}
		
		//------------------------------------------------渲染部分----------------------------------------------
		//记录自身当前所在的渲染树
		private var _renderTree:RenderTree;
		//记录自身的渲染深度
		private var _depth:int = 0;
		
		//将来可能做什么混合之类的，目前要写UV动画先弄个测试
		public var useAlphaTexture:Boolean = false;
		
		
		//获取自身当前所在的渲染树
		public function get renderTree():RenderTree{
			return _renderTree;
		}
		
		//设置自身当前所在的渲染树
		public function set renderTree(value:RenderTree):void{
			_renderTree = value;
		}
		
		//获取自身的渲染深度
		public function get depth():int{
			return _depth;
		}
		
		//设置自身的渲染深度
		public function set depth(value:int):void{
			_depth = value;
		}
		
		//----------------override -----------------
		
		override public function onDraw():void 
		{
			Stage3DProxy.renderTriangles += geometry.numTriangles
			
			material.draw(geometry,Stage3DProxy.context3d);
		}
			
	}

}